package com.xmut.bs.handaccount.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.xmut.bs.handaccount.R;

import butterknife.BindView;


/**
 * Author Dollkey
 * Date 2017/9/5 10:07.
 */

public abstract class ToolbarBaseFragment extends BaseFragment {


    @BindView(R.id.toolbar)
    Toolbar mToolbar;


    /**
     * 设置标题文本
     */
    protected abstract String getSubTitle();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        setHasOptionsMenu(true);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mToolbar.setBackgroundColor(colorPrimary);
        if (getContentViewLayoutID() != 0) {
            initToolbar();
        }
    }

    private void initToolbar() {
        if (mToolbar != null){
            mToolbar.setTitle(getSubTitle());
            ((AppCompatActivity) getActivity()).setSupportActionBar(mToolbar);
        }
    }
//
//    public int getMenuId(){
//        return R.menu.toolbar_search;
//    }
//
//    @Override
//    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
//        inflater.inflate(getMenuId(),menu);
//        super.onCreateOptionsMenu(menu, inflater);
//    }
//
//    public void onMenuItemClick(MenuItem item){
//
//    }
//
//    @Override
//    public boolean onOptionsItemSelected(MenuItem item) {
//        onMenuItemClick(item);
//        switch (item.getItemId()) {
//            case R.id.menu_search:
//                Log.i(Constants.TAG, "action android selected");
//                return true;
//            default:
//                return super.onOptionsItemSelected(item);
//        }
//    }
}
